home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / M7SEND.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  6KB  |  178 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                  This module was written by Bob Hartman                  */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                 BinkleyTerm Modem7 Sender State Machine                  */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. int MSInit (XMARGSP, int);
  51. int MSEnd (XMARGSP, int);
  52. int MSWaitNak (XMARGSP);
  53. int MSWaitChAck (XMARGSP);
  54. int MSWaitCksm (XMARGSP);
  55.  
  56. STATES Modem7_Sender[] = {
  57.    { "MSInit",  MSInit },
  58.    { "MSEnd",  MSEnd },
  59.    { "MS0",  MSWaitNak },
  60.    { "MS1",  MSWaitChAck },
  61.    { "MS2",  MSWaitCksm }
  62. };
  63.  
  64. int MSInit (XMARGSP args, int start_state)
  65. {
  66.    char *p;
  67.    int i;
  68.    struct FILEINFO dta;
  69.  
  70.    XON_DISABLE ();
  71.    args->tries = 0;
  72.    (void) dfind (&dta, args->filename, 0);
  73.    (void) strcpy (args->m7name, "           ");
  74.    for (i = 0, p = dta.name; i < 8; p++, i++)
  75.       if ((*p != '.') && (*p != '\0'))
  76.          args->m7name[i] = (char)toupper(*p);
  77.       else
  78.          break;
  79.  
  80.    if (*p == '.')
  81.       ++p;
  82.    for (i = 8; i < 11; p++, i++)
  83.       if ((*p != '.') && (*p != '\0'))
  84.          args->m7name[i] = (char)toupper(*p);
  85.       else
  86.          break;
  87.  
  88.    /* Now do the checksum */
  89.    args->check = SUB;
  90.    for (i = 0; i < 11; i++)
  91.       args->check += (unsigned char) args->m7name[i];
  92.  
  93.    return (start_state);
  94. }
  95.  
  96. int MSEnd (XMARGSP args, int cur_state)
  97. {
  98.    args->result = cur_state;
  99.    return (cur_state);
  100. }
  101.  
  102. int MSWaitNak (XMARGSP args)
  103. {
  104.    if (args->tries >= 10)
  105.       return (FNAME_ERR);
  106.  
  107.    if (!CARRIER)
  108.       return (CARRIER_ERR);
  109.  
  110.    if (TIMED_READ (10) != NAK)
  111.       {
  112.       ++args->tries;
  113.       return (MS0);
  114.       }
  115.  
  116.    SENDBYTE (ACK);
  117.    SENDBYTE ((unsigned char) *(args->m7name));
  118.    args->fptr = args->m7name + 1;
  119.    return (MS1);
  120. }
  121.  
  122. int MSWaitChAck (XMARGSP args)
  123. {
  124.    if (!CARRIER)
  125.       return (CARRIER_ERR);
  126.  
  127.    if (TIMED_READ (10) != ACK)
  128.       {
  129.       ++args->tries;
  130.       SENDBYTE ('u');
  131.       return (MS0);
  132.       }
  133.  
  134.    /* If filename done */
  135.    if (*(args->fptr) == '\0')
  136.       {
  137.       SENDBYTE (SUB);
  138.       return (MS2);
  139.       }
  140.    else
  141.       {
  142.       /* Send next char of name */
  143.       SENDBYTE ((unsigned char) *args->fptr++);
  144.       return (MS1);
  145.       }
  146. }
  147.  
  148. int MSWaitCksm (XMARGSP args)
  149. {
  150.    int in_char;
  151.  
  152.    if (!CARRIER)
  153.       return (CARRIER_ERR);
  154.  
  155.    if (((in_char = TIMED_READ (10)) < 0) || ((unsigned char)in_char != args->check))
  156.       {
  157.       SENDBYTE ('u');
  158.       ++args->tries;
  159.       return (MS0);
  160.       }
  161.    else
  162.       {
  163.       SENDBYTE (ACK);
  164.       return (SUCCESS);
  165.       }
  166. }
  167.  
  168. int Modem7_Send_File (char *filename)
  169. {
  170.    XMARGS batch;
  171.    int res;
  172.  
  173.    batch.result = 0;
  174.    batch.filename = filename;
  175.    res = state_machine (Modem7_Sender, &batch, 2);
  176.    return (res);
  177. }
  178.